import api from './index'

export interface DashboardStats {
  totalProblems: number
  totalSubmissions: number
  totalUsers: number
  totalCourses: number
  totalClasses: number
  totalAssignments: number
  successRate: number
  onlineUsers: number
  recentSubmissions: number
  pendingSubmissions: number
}

export interface UserStats {
  mySubmissions: number
  completedAssignments: number
  pendingAssignments: number
  mySuccessRate: number
  myCourses: number
  myClasses: number
}

export interface TeacherStats {
  myCourses: number
  myProblems: number
  pendingSubmissions: number
  studentCount: number
  myAssignments: number
  myClasses: number
}

export interface AdminStats {
  totalProblems: number
  totalSubmissions: number
  totalUsers: number
  totalCourses: number
  totalClasses: number
  totalAssignments: number
  successRate: number
  onlineUsers: number
  systemStatus: string
  recentActivities: number
}

export const statisticsApi = {
  // 获取仪表板统计数据
  getDashboardStats(): Promise<DashboardStats> {
    return api.get('/statistics/dashboard')
  },

  // 获取用户个人统计数据
  getUserStats(): Promise<UserStats> {
    return api.get('/statistics/user')
  },

  // 获取教师统计数据
  getTeacherStats(): Promise<TeacherStats> {
    return api.get('/statistics/teacher')
  },

  // 获取管理员统计数据
  getAdminStats(): Promise<AdminStats> {
    return api.get('/statistics/admin')
  },

  // 获取在线用户数
  getOnlineUsers(): Promise<{ onlineUsers: number }> {
    return api.get('/statistics/online-users')
  },

  // 获取系统状态
  getSystemStatus(): Promise<{ status: string; uptime: number; memory: number; cpu: number }> {
    return api.get('/statistics/system-status')
  }
}
